<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Used to wrap form elements into some tags
 *
 * @author chaporgin_a
 */
abstract class VA_Form_Decorator {
  private $element;
  protected function  __construct($options) {

  }
  public function setElement(VA_Form_FormElement $element) {
    $this->element = $element;
    return $this;
  }
//  /**
//   *
//   * @param string $key
//   * @param array $options
//   * @return mixed
//   */
//  protected function getOption($key, &$options) {
//    if(!key_exists($key, $options))
//      throw new Exception(get_class($this).' must have '.$key.' option!');
//    return $options[$key];
//
//  }
  /**
   *
   * @param string $key
   * @param array $options
   * @param  $default
   * @return <type>
   */
  protected function getOption($key, &$options, $default = null) {
    if( (null === $default) && !key_exists($key, $options))
      throw new Exception(get_class($this).' must have '.$key.' option!');
    return key_exists($key, $options)?$options[$key]:$default;
  }
  /**
   *
   * @return VA_Form_FormElement
   */
  public function getElement() {
    return $this->element;
  }
  /**
   * Use it to render form elements
   *
   * @param string $content
   */
  abstract public function render($content);
  static public function Generate($shortName, $options = array()) {
    $className = 'VA_Form_Decorator_'.$shortName;
    eval('$return = new '.$className.'($options);');
    return $return;
  }
}